package cn.tedu.egmvc2.demos.web.controller;

import cn.tedu.egmvc2.demos.web.mapper.AddressMapper;
import cn.tedu.egmvc2.demos.web.pojo.dto.AddressDto;
import cn.tedu.egmvc2.demos.web.pojo.entity.Address;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("address")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;

    @RequestMapping("insert")
    public String insertAddress(AddressDto addressDto){
        Address address = new Address();
        BeanUtils.copyProperties(addressDto ,address);
        addressMapper.addressInsert(address);
        return "插入成功";
    }

    @RequestMapping("delete")
    public String deleteAddress (int id){
        addressMapper.delete(id);
        return "删除成功";
    }

    @RequestMapping("updete")
    public String  update(Address address ){
        addressMapper.update(address);
        return "改好 了";
    }

    @RequestMapping("select")
    public List<Address> select(){

        return addressMapper.select();
    }



}
